<?php
/**
 * 更新商品基础数据
 *
 */
$argv[1] = 'dev.fh.taoex.com';
$argv[2] = '2012-11-16 00:00:00';
$argv[3] = '2012-11-16 23:59:59';

$domain = $argv[1];
$sDate = time()-86400;//strtotime($argv[2]);
$eDate = time();//strtotime($argv[3]);


define('COMMAND_MODE', true);

set_time_limit(0);
define('LIB_DIR', dirname(__FILE__) . '/lib/');
require_once(LIB_DIR . 'api/taobao/order.php');
require_once(dirname(__FILE__) . '/lib/init.php');

updateGoods();

function updateGoods() {




	$db = kernel::database();

	$row = 0;
	$n=0;
	$e=0;
	$handle = fopen("data/pkg.csv","r");
	while ($data = fgetcsv($handle, 1000, ",")) {
		$num = count($data);
		//echo "			$num fields in line $row:			\n";
		$row++;
		// 				for ($c=0; $c < $num; $c++) {
		// 					echo $data[$c] . "
		// 					\n";
		// 				}
			
			

		$pkgbn=$data[0];
		$pkgname=$data[1];
		$bn=trim($data[2]);
		$pkgnum=$data[3];
			
			


			
		$sql = "select product_id,name from `sdb_ome_products` where bn='$bn'";
		$r = $db->select($sql);
		$product_id =  $r[0]['product_id'];
		$product_name = $r[0]['name'];

		if($product_id >0){
			//插入捆绑商品
			$sql1 = "insert into  `sdb_omepkg_pkg_goods` (pkg_bn ,name)value('$pkgbn','$pkgname')";
			//$db->exec($sql1);
			//$goodid=$db->lastinsertid();
			$n++;
			echo $sql1."\n";
			//插入捆绑货品
			$sql2 = " insert into `sdb_omepkg_pkg_product`(product_id,bn,name,goods_id,pkgnum)value($product_id,'$bn','$product_name',$goodid,$pkgnum)";
			echo $sql2."\n";

			//$db->exec($sql2);


			echo "已更新,".$pkgbn.','.$pkgname.",".$bn."\n";
		}else{

			echo "未更新,".$pkgbn.','.$pkgname.",".$bn."\n";

		}

			
	}
	fclose($handle);

	echo "更新".$n."共".$row."错误".$e;


}